import router from "./index";
import state from '../store/public/state'


export default () => {
  router.beforeEach(async(to, from, next) => {
    const redirectObj = state.redirectObj
    // console.log(to)
    if (localStorage.getItem('author_token')) { // 判断是否登录
      

      // 开发完解除
      if(redirectObj[to.name]) {
        next({name: redirectObj[to.name]})
      }else {
        if(to.meta.show) {
          next()
        }else {
          next({
            path: '/404'
          })
        }
      }

      // next();

    } else if (to.path === '/login') {
      next()
    } else {
      localStorage.clear()
      next({
        path: '/login'
      })
    }
    // next()
  });
}
